﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CustomerArchives_CustomerPreferenceMain : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200500102");
        if (!IsPostBack)
        {
            BindDataListPreferences();
        }
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    private void BindDataListPreferences()
    {
        string strSql = "";
        if (txtInput.Text != "")
        {
            if (DropDownList1.SelectedValue == "0")
            {
                strSql += " and Preference_ID like '%" + txtInput.Text.Trim() + "%' ";
            }
            else if (DropDownList1.SelectedValue == "1")
            {
                strSql += " and Preference_Name like '%" + txtInput.Text.Trim() + "%' ";
            }
        }

        int pageCount, rowCount;
        DataSet ds = new BLL.CustomerPreferenceMain().GetCustomerPreference(GetStartIndex(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize), AspNetPager1.PageSize, strSql, out rowCount);
        dlistPreferences.DataSource = ds;
        dlistPreferences.DataBind();
        AspNetPager1.RecordCount = rowCount;
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200500102", "00001"))
        {
            Share.Alert(this.Page, "无权操作！"); return;
        }
        Response.Redirect("AddCustomerPreference.aspx");
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;
        BindDataListPreferences();
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindDataListPreferences();
    }

    private int GetStartIndex(int pageIndex, int pageSize)
    {
        return 1 + (pageIndex - 1) * pageSize;
    }
}
